require('@/public.js');
require('@/assets/css/drag-up.scss');
import { getWindowWidthAndHeight } from '@/utils/utils';

Jsborya.ready(function () {


	var app = new Vue({
		el: '#app',
		data: {
			isPullLoad: true,//上拉加载开关
			isHaveMore: 0,//是否还有更多号码
			firstLoad: true,
			pageSize: 12,
			pageNum: 0,//当前页数
			boxHeight: '400px',
			dataList: [],
		},
		created: function () {
			Jsborya.webviewLoading({ isLoad: false });//关闭app加载层
		},
		mounted: function () {
			const vm = this;

			// 获取窗口宽高
			let { windowHeight } = getWindowWidthAndHeight();
			vm.boxHeight = windowHeight + 'px';

			Jsborya.getUserInfo(function (data) {
				vm.userInfo = data;

				vm.getList();
			});
		},
		methods: {
			getList: function (page, closeLoad) {
				const vm = this;

				var json = {
					'params': {
						'pageSize': vm.pageSize,
						'pageNum': page || 1,
					},
					'userInfo': vm.userInfo
				};

				vm.isHaveMore = false;
				var pull = function (data) {//上拉时，合并数据列表
					vm.dataList = vm.dataList.concat(data);
				};
				if (json.params.lastId == 0) {
					document.getElementById('dataBox').scrollTop = 0;
				}
				vm.AJAX('/jleas/w/order/buyModel', json, function (data) {
					vm.firstLoad = false;
					vm.alreadyPhone = '';
					vm.isPullLoad = true;
					vm.pageNum = json.params.pageNum;

					closeLoad ? pull(data.data.list) : vm.dataList = data.data.list;
					if (json.params.pageNum != 1 && data.data.list.length == 0) vm.isHaveMore = true;
				}, closeLoad);
			},
			jumpDeliveryInfo (cargoCompy, cargoId) {
				Jsborya.pageJump({
					url: `http://m.kuaidi100.com/result.jsp?nu=${cargoId}`,
					stepCode: '800',
					depiction: '物流详情',
					destroyed: false,
				});
			},
			pullLoad: function (e) {//上拉执行
				e.preventDefault();
				var vm = this, page = vm.pageNum, obj = document.getElementById('dataBox');
				console.log(page)
				if (vm.isPullLoad && obj.scrollHeight <= (obj.scrollTop + obj.offsetHeight) && !vm.isHaveMore) {
					vm.isPullLoad = false;
					page++;
					vm.getList(page, true);
				} else {
					vm.isHaveMore = false;
				}
			},
		}
	});


});